<template>
  <div class="pd-20">
    <el-button type="primary"
               @click="handleOption(null, 'add')">新 增</el-button>
    <element-table :columns="columns"
                   class="mt-20"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:edit="{row}">
        <el-button type="primary"
                   @click="handleOption(row, 'edit')">编 辑</el-button>
        <el-button type="danger"
                   @click="handleOption(row, 'del')">删 除</el-button>
      </template>
    </element-table>
    <complications-dialog :dataObj="dataObj"
                          v-if="isShow"
                          :visible.sync="isShow"></complications-dialog>
  </div>
</template>
<script>
import elementTable from '@/base/ElementTable'
import complicationsDialog from './complicationsDialog'
export default {
  name: 'complications', // 合并症管理
  data () {
    return {
      loading: false,
      isShow: false,
      columns: [
        {
          label: '合并症名称',
          prop: 'name',
        },
        {
          label: '操作',
          prop: 'edit',
          isSlot: true
        }
      ],
      tableData: [],
      pageTotal: 0,
      pageIndex: 1,
      pageSize: 20,
      dataObj: {},
      name: ''
    }
  },
  methods: {

    getList () {
      this.post(this.api.healthMap.getHealthMapArteriosclerosis, {
        pageIndex: this.pageIndex - 1,
        pageSize: this.pageSize,
      }).then(res => {
        if (res.data.code === '200') {
          this.tableData = res.data.object;
          this.pageTotal = res.data.totalNum;
        }
      })
    },
    handleOption (row, op) {
      switch (op) {
        case 'add':
          this.dataObj = null;
          this.isShow = true;
          break;
        case 'edit':
          this.isShow = true;
          this.dataObj = Object.assign({}, row);
          break;
        case 'del':
          this.$confirm('您是否要删除该合并症？')
            .then(async _ => {
              const { data: res } = await this.post(this.api.healthMap.delHealthMapArteriosclerosis, {
                id: row.id
              })
              if (res.code === '200') {
                this.$message.success('删除成功!')
                this.getList()
              }
            })
            .catch(_ => { });
          break;
      }
    },
    // 分页
    handleChangePage (page) {
      this.pageIndex = page;
      this.getList();
    },
  },
  created () {
    this.getList();
  },
  components: {
    'element-table': elementTable,
    'complications-dialog': complicationsDialog
  }
}
</script>
<style scoped lang="scss">
</style>
